<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>课程-助教个人任务</title>

<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/courseAssistantTask.css'/>" />
<link rel="stylesheet" type="text/css" href="<c:url value='/css/classTask-stu.css'/>" />
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/wangEditor/dist/css/wangEditor.css'/>" />
<script src="<c:url value='/js/courseAssistantTask.js'/>" type="text/javascript" charset="utf-8"></script>

</head>
<body>
	<div class="container-fluid main">
		<div class="row">
			<div class="col-md-12">
				<%@include file="/common/header.jsp"%>
			</div>
			<div class="col-md-12">
				<%@include file="common/courseHeader.jsp"%>
			</div>
			<div class="col-md-3">
				<%@include file="common/courseLeft.jsp"%>
			</div>
			<div class="col-md-9">
				<%@include file="common/courseNavbar.jsp"%>
			</div>
			<div class="col-md-9">
				<!-- 任务首页 -->
				<div class="row">
					
					<div class="col-md-12">
						<!--任务列表 -->
						<div id="assi-task-list">
							<table class="table table-hover">
								<thead>
									<tr>
										<th>任务名</th>
										<th>发布时间</th>
										<th>发布者</th>
										<th>
											<select onchange="search()" class="form-control" id="taskStatus">
												<option value="ALL">全部</option>
												<option value="UNCOMMITTED">未提交</option>
												<option value="COMMITTED">已提交</option>
												<option value="HAVEREAD">已批改</option>
											</select>
										</th>
									</tr>
								</thead>
								<tbody id="taskList">
									
								</tbody>
							</table>
							<!-- 分页 -->
							<div class="page-content" id="assistantTaskPage">
								<nav class="pagination" role="navigation">
									<a class="last-page">
										<i class="fa fa-angle-left"></i>
									</a>
									<span class="page-number">...</span>
									<a class="next-page">
										<i class="fa fa-angle-right"></i>
									</a>
								</nav>
							</div>
						</div>
						
						<!-- 助教编辑任务答案&&提交任务 -->
						<div id="assi-task-edit-box" style="display:none;">
							<%@include file="assistantTaskDetail.jsp"%>
						</div>
						
					</div>
				</div>
			</div>
		</div>
		
	</div>
	
	
	
	<%@include file="/common/footer.jsp"%>
	
</body>

<script>
var data=${data};
$(document).ready(function() {
	if (data.status != "success") {
		alert(data.message);
		return;
	}
	$("#assi-task").css("color","#00b43c");
	fetchCourse(data.data.courseId);
	initTable(data.data);
	changeUrl(data.data.courseId);
})

var getStatus = function(status){
	 if(status == "UNCOMMITTED"){
		 return "未提交";
	 }else if(status == "COMMITTED"){
		 return "已提交";
	 }else if(status == "HAVEREAD"){
		 return "已批阅";
	 }
 }
 
var initTable = function(data){
	var list=data.list;
	var taskList = $("#taskList");
	taskList.empty();
	if(list.length < 1){
		var s="<tr>没有当前状态的任务</tr>";
		taskList.append(s);
	}else {
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="<tr onclick=\"getTaskPersonalDetail("+item.taskId+")\">";
				s+="<td title=\""+item.title+"\">"+item.title+"</td>";
				s+="<td title=\""+item.assignDate+"\">"+item.assignDate+"</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				s+="<td title=\""+getStatus(item.taskStatus)+"\">"+getStatus(item.taskStatus)+"</td>";
				s+="</tr>";
			taskList.append(s);
		}
	}	
	initPages(data.pageNo,data.allpages);
}

var search = function(){
	var json = {
			courseId:data.data.courseId,
			pageNo:1	
	};
	var taskStatus=$("#taskStatus  option:selected").val();
	if(taskStatus != "ALL"){
		json.taskStatus=taskStatus;
	}
	getList(json);
}

var getList = function(json){
	
	$.get(CONTEXT_PATH+"taskPersonAssistantList/ajaxListData", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			initTable(data.data);
		}else{
			alert(data.message);
		}
	});
	
}

var initPages = function(pageNo,allpages){
	
	var lastPageObj=$("#assistantTaskPage .last-page");
	var nextPageObj=$("#assistantTaskPage .next-page");
	var pageNumberObj=$("#assistantTaskPage .page-number");
	var lastPage=pageNo-1;
	if(lastPage<=0){//设置disableed
		lastPage=1;
	}else{
		 $("#assistantTaskPage .last-page").bind("click",{pageNo:lastPage},getPage);
	};
	var nextPage = pageNo+1;
	if(nextPage>allpages){
		nextPage=allpages;
	}else{
		 $("#assistantTaskPage .next-page").bind("click",{pageNo:nextPage}, getPage);
	}
	if(allpages<=1){
		$("#assistantTaskPage").hide();
	}else{
		$("#assistantTaskPage").show();
		pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
	}		
}
var getPage = function(event){
	var json = {
			courseId:data.data.courseId,
			pageNo:1	
	};
	var taskStatus=$("#taskStatus  option:selected").val();
	if(taskStatus != "ALL"){
		json.taskStatus=taskStatus;
	}
	json.pageNo=event.data.pageNo;
	getList(json);
}

var getDetail = function(taskId){
	var json = {
			taskId:taskId
	};
	$.get(CONTEXT_PATH+"taskPersonAssistantDetail/ajaxDetail", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){			
			alert(JSON.stringify(data.data.view));//数据
			initDetail(data.data.view);//初始化详情
		}else{
			alert(data.message);
		}
	});
	
}

var initDetail = function(view){
	$("#title").text(view.title);
	$("#deadline").text(view.deadline);
	$("#description").html(view.description);
	
	var attachList=$("#attachList");
	attachList.empty();
	for(var i=0;i<view.attachment.files.length;i++){
		var item=view.attachment.files[i];
		var s="<li>";
		s+="<span class=\"file-name-date\" title=\""+item.name+"\">"+item.name+"</span>";
		s+="<span class=\"file-upload-stu\"><a href=\"<c:url value='/resource/download/"+item.url+"'/>\">下载</a></span>";
		s+="</li>";
		attachList.append(s);
	}
	if(view.submitResult.isAnswerShow=="YES"){
		$("#answer-box").show();
		$("#standardAnswer").html(view.standardAnswer);
		var answerAttachList=$("#answerAttachList");
		answerAttachList.empty();
		for(var i=0;i<view.answerAttachment.files.length;i++){
			var item=view.answerAttachment.files[i];
			var s="<li>";
			s+="<span class=\"file-name-date\" title=\""+item.name+"\">"+item.name+"</span>";
			s+="<span class=\"file-upload-stu\"><a href=\"<c:url value='/resource/download/"+item.url+"'/>\">下载</a></span>";
			s+="</li>";
			answerAttachList.append(s);
		}
	} else {
		$("#answer-box").hide();
	}
	
	
	if(view.submitResult.status=="COMMITTED"){
		$("#submitDetail").html(view.submitResult.detail);
		var submitList=$("#stu-submit-file-list");
		submitList.append(s);
		for(var i=0;i<view.submitResult.resultAttachment.files.length;i++){
			var item=view.submitResult.resultAttachment.files[i];
			var s="<li>";
			s+="<span class=\"file-name-date\" title=\""+item.name+"\">"+item.name+"</span>";
			s+="<span class=\"file-upload-stu\"><a href=\"<c:url value='/resource/download/"+item.url+"'/>\">下载</a></span>";
			s+="</li>";
			submitList.append(s);
		}
		$(".correct-info").hide();
		$("#no-correct").show();
		$("#task-submit-btn").prop("disabled",true);
	} else if(view.submitResult.status=="UNCOMMITTED") {
		$(".correct-info").hide();
		$("#no-correct").hide();
		$("#task-submit-btn").show();
	} else if(view.submitResult.status=="HAVEREAD"){
		$("#submitDetail").html(view.submitResult.detail);
		var submitList=$("#stu-submit-file-list");
		submitList.append(s);
		for(var i=0;i<view.submitResult.resultAttachment.files.length;i++){
			var item=view.submitResult.resultAttachment.files[i];
			var s="<li>";
			s+="<span class=\"file-name-date\" title=\""+item.name+"\">"+item.name+"</span>";
			s+="<span class=\"file-upload-stu\"><a href=\"<c:url value='/resource/download/"+item.url+"'/>\">下载</a></span>";
			s+="</li>";
			submitList.append(s);
		}
		$(".correct-info").show();
		$("#teacher-score").text(view.submitResult.score);
		$("#teacher-comment").html(view.submitResult.evaluate);
		$("#up-file-btn").hide();
		$("#no-correct").hide();
		$("#task-submit-btn").hide();
	}

}
</script>

</html>